package com.shop2cn.iapi.grouponmgr.testcase;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.grouponmgr.parameter.DeleteGrouponBean;
import com.shop2cn.iapi.grouponmgr.parameter.SaveGrouponReq;
import com.shop2cn.iapi.grouponmgr.service.DeleteGrouponCall;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.Shop2cnGrouponCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.GrouponProducts;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*删除拼团Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteGroupon{
	private static DeleteGrouponBean deletegrouponBean;
	private static DeleteGrouponCall deletegrouponCall;
	YmtProductsIWapper YmtProductsIWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除拼团Test");
	}

	@Before
	public void caseUp() {
		deletegrouponBean=new DeleteGrouponBean();
		deletegrouponCall=new DeleteGrouponCall();
		YmtProductsIWapper=new YmtProductsIWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deletegrouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteGroupon_001() {
		Logger.start(true,"删除团成功");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-2,"yyyy-MM-dd HH:mm:ss"));
			String dateBeforeOrNextSecond = YMTDateUtil.getDateBeforeOrNextSecond(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"),2);
			savegrouponBean.setEndTime(dateBeforeOrNextSecond);
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Thread.sleep(3000);
			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(mchId);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("200", deletegrouponCall.getString("code"), "验证code");
			int asInt = deletegrouponCall.getJsonObject().get("data").getAsInt();
			Logger.verifyEquals(asInt, grouponProductId, "验证删除的拼团id是否正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteGroupon_002() {
		Logger.start(true,"不输入sellerId失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-2,"yyyy-MM-dd HH:mm:ss"));
			String dateBeforeOrNextSecond = YMTDateUtil.getDateBeforeOrNextSecond(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"),2);
			savegrouponBean.setEndTime(dateBeforeOrNextSecond);
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Thread.sleep(3000);
			deletegrouponBean.setGrouponProductId(grouponProductId);
//			deletegrouponBean.setSellerId(mchId);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("400", deletegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteGroupon_003() {
		Logger.start(true,"不输入grouponProductId失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-2,"yyyy-MM-dd HH:mm:ss"));
			String dateBeforeOrNextSecond = YMTDateUtil.getDateBeforeOrNextSecond(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"),2);
			savegrouponBean.setEndTime(dateBeforeOrNextSecond);
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Thread.sleep(3000);
//			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(mchId);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("400", deletegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteGroupon_004() {
		Logger.start(true,"grouponProductId和sellerid不匹配失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-2,"yyyy-MM-dd HH:mm:ss"));
			String dateBeforeOrNextSecond = YMTDateUtil.getDateBeforeOrNextSecond(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"),2);
			savegrouponBean.setEndTime(dateBeforeOrNextSecond);
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Thread.sleep(3000);
			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(123123);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("200", deletegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteGroupon_005() {
		Logger.start(true,"对一个拼团进行反复删除");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-2,"yyyy-MM-dd HH:mm:ss"));
			String dateBeforeOrNextSecond = YMTDateUtil.getDateBeforeOrNextSecond(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"),2);
			savegrouponBean.setEndTime(dateBeforeOrNextSecond);
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Thread.sleep(3000);
			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(mchId);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("200", deletegrouponCall.getString("code"), "验证code");
			
			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(mchId);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("200", deletegrouponCall.getString("code"), "验证code");

			
		} catch (Exception e) {
			
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteGroupon_006() {
		Logger.start(true,"正在进行的拼团，删除失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(mchId);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("201", deletegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteGroupon_007() {
		Logger.start(true,"还没有开始的拼团，删除失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(1,"yyyy-MM-dd HH:mm:ss"));
			savegrouponBean.setEndTime(YMTDateUtil.getBeforeOrNextDay(3,"yyyy-MM-dd HH:mm:ss"));
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(mchId);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("201", deletegrouponCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_DeleteGroupon_008() {
		Logger.start(true,"还没有开始的拼团，删除失败");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(mchId,"AutoTest",false);
			String pid = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			List<String> catalogList =new ArrayList<String>();
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(mchId,pid);
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			SaveGrouponReq savegrouponBean = Shop2cnGrouponCallService.initSaveGrouponReq(mchId, pid, catalogList.get(0), 100d);
			savegrouponBean.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-2,"yyyy-MM-dd HH:mm:ss"));
			String dateBeforeOrNextSecond = YMTDateUtil.getDateBeforeOrNextSecond(YMTDateUtil.getSysTime("yyyy-MM-dd HH:mm:ss"),2);
			savegrouponBean.setEndTime(dateBeforeOrNextSecond);
			Integer grouponProductId = Shop2cnGrouponCallService.SaveGrouponCall(savegrouponBean);
			Thread.sleep(3000);
			deletegrouponBean.setGrouponProductId(grouponProductId);
			deletegrouponBean.setSellerId(11223344);
			deletegrouponCall.setData(deletegrouponBean);
			deletegrouponCall.callService();			
			Logger.verifyEquals("200", deletegrouponCall.getString("code"), "验证code");
			int asInt = deletegrouponCall.getJsonObject().get("data").getAsInt();
			Logger.verifyEquals(asInt, grouponProductId, "验证删除的拼团id是否正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}